cmake_minimum_required(VERSION 2.6)

project(gaitrec)
list(APPEND CUDA_NVCC_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "-std=c++0x")
add_definitions(-std=c++11)
add_definitions(-DAPI_EXPORTS)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)

set(ENV_ROOT "C:/Users/NH-001/Desktop/env")

# OpenCV
set(OPENCV_PATH "${ENV_ROOT}/OpenCV")
include_directories("${OPENCV_PATH}/include")
link_directories("${OPENCV_PATH}/x64/vc15/lib")

# OpenSSL
set(OPENSSL_PATH "${ENV_ROOT}/OpenSSL-Win64")
include_directories("${OPENSSL_PATH}/include")
link_directories("${OPENSSL_PATH}/lib")

# Eigen3
include_directories("${ENV_ROOT}/eigen")

# Dirent
include_directories("${ENV_ROOT}/dirent/include")

# CUDA
find_package(CUDA REQUIRED)
set(CUDA_NVCC_PLAGS ${CUDA_NVCC_PLAGS};-std=c++11;-g;-G;-gencode;arch=compute_53;code=sm_53)
if(WIN32)
enable_language(CUDA)
endif(WIN32)
set(CUDA_PATH "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.6")
include_directories("${CUDA_PATH}/include")
link_directories("${CUDA_PATH}/lib/x64")

# TensorRT
set(TRT_DIR "${ENV_ROOT}/TensorRT-8.4.0.6")
include_directories("${TRT_DIR}/include")
link_directories("${TRT_DIR}/lib")

# ===== deepsort =====
include_directories("${PROJECT_SOURCE_DIR}/deepsort/include")
aux_source_directory("${PROJECT_SOURCE_DIR}/deepsort/src" DEEPSORT_SRC_DIR)
add_library(deepsort STATIC ${DEEPSORT_SRC_DIR})
target_link_libraries(deepsort 
    "${OPENCV_PATH}/x64/vc15/lib/opencv_world400d.lib"
    "${TRT_DIR}/lib/*.lib"
)

# ===== yolo =====
include_directories("${PROJECT_SOURCE_DIR}/yolo/include")
aux_source_directory("${PROJECT_SOURCE_DIR}/yolo/src" YOLO_SRC_DIR)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
cuda_add_library(yolov5_trt STATIC ${YOLO_SRC_DIR})
target_link_libraries(yolov5_trt deepsort)


# features db
set(REDIS_PATH "C:/Users/NH-001/Desktop/muhaobing/projects/Features_DB")
include_directories("C:/Users/NH-001/Desktop/env/redis-3.0/deps/hiredis")
include_directories("${REDIS_PATH}/include")
link_directories("${REDIS_PATH}/lib")

# ===== main =====
include_directories("${PROJECT_SOURCE_DIR}/include")
aux_source_directory("${PROJECT_SOURCE_DIR}/src" MAIN_SRC_DIR)
add_executable(gaitrec ${MAIN_SRC_DIR})
target_link_libraries(
gaitrec yolov5_trt
"${OPENSSL_PATH}/lib/libssl.lib"
"${OPENSSL_PATH}/lib/libcrypto.lib"
"${FFMPEG_PATH}/lib/*.lib"
"${REDIS_PATH}/lib/featuredb.lib"
)

if(UNIX)
add_definitions(-O2 -pthread)
endif(UNIX)
set(CMAKE_CXX_FLAGS "-std=c++0x")